//
//  HNAttack.m
//  HeroNuts
//
//  Created by Magic on 4/2/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "HNAttack.h"
#import "HNAudioEngine.h"


@implementation HNAttack

#pragma mark HNAttack - initialization - preparing the action sequence to be run

- (id)initWithActorName:(NSString *)actor direction:(NSString *)direction
{
    NSString *actionName = [NSString stringWithFormat:@"ATTACK_%@",direction];
    if ( (self = [super initWithActorName:actor action:actionName]) ) {     
    }
        
    return self;
}

- (void)playSoundEffect
{
    [[HNAudioEngine sharedEngine] playSoundEffectWithActor:target_.name action:@"ATTACK"];
}

#pragma mark HNAttack - running the action sequence

- (void)startWithTarget:(HNActor *)aTarget
{
    target_ = aTarget;
    
    CCSpawn *attackWithSound = [actions_ objectAtIndex:0];    
    CCCallFunc *endAttack = [CCCallFunc actionWithTarget:self selector:@selector(restore)];
    CCSequence *attack = [CCSequence actionOne:attackWithSound two:endAttack];
    
    CCDelayTime *delay = [CCDelayTime actionWithDuration:attackWithSound.duration/2];
    CCCallFunc *delayFinish = [CCCallFunc actionWithTarget:self selector:@selector(notifyCompletion)];
    
    CCSpawn *spawn = [CCSpawn actionOne:attack two:[CCSequence actionOne:delay two:delayFinish]];
    
    [target_.sprite runAction:spawn];
}

- (void)onRestoreFinished
{      
}

@end
